package br.usp.ime.origami.foldcut.gui.util;

import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Shape;
import java.awt.Stroke;

public class OrigamiShape implements Comparable<OrigamiShape>
{
	private DrawScheme scheme;

	private Shape shape;

	public OrigamiShape(Shape shape, DrawScheme scheme)
	{
		this.shape = shape;
		this.scheme = scheme;
	}

	public DrawScheme getScheme()
	{
		return scheme;
	}

	public Shape getShape()
	{
		return shape;
	}

	public int compareTo(OrigamiShape o)
	{
		OrigamiShape other = (OrigamiShape) o;

		return OrigamiShape.DrawScheme.getPriority(other.getScheme()).getValue()
				- OrigamiShape.DrawScheme.getPriority(this.scheme).getValue();
	}

	public Color getColor()
	{
		return DrawScheme.getColor(this.scheme);
	}

	public Stroke getStroke()
	{
		return DrawScheme.getStroke(this.scheme, 0);
	}

	public enum DrawScheme
	{
		MOUNTAIN, VALLEY, SUPER_MOUNTAIN, SUPER_VALLEY, DISK, VERTEX, EDGE, LINE, EDGE_IN_PAPER, EDGE_IN_POLYGON, EDGE_CUT, EDGE_UNCOVERED;

		public static Color getColor(DrawScheme scheme)
		{

			switch (scheme)
			{
			case MOUNTAIN:
			case SUPER_MOUNTAIN:
				return Color.BLUE;
			case VALLEY:
			case SUPER_VALLEY:
				return Color.RED;
			case DISK:
				return Color.YELLOW;
			case VERTEX:
				return Color.BLACK;
			case EDGE:
				return Color.BLACK;
			case EDGE_IN_PAPER:
				return Color.BLACK;
			case EDGE_IN_POLYGON:
				return Color.BLACK;
			case EDGE_CUT:
				return Color.GREEN;
			}

			return Color.BLACK;
		}

		public static boolean mustFill(DrawScheme scheme)
		{
			switch (scheme)
			{
			case DISK:
			case VERTEX:
				return true;
			}
			return false;
		}

		public static Stroke getStroke(DrawScheme scheme, float d)
		{

			switch (scheme)
			{
			case MOUNTAIN:
				return new BasicStroke(1 + d, 0, 0, 1, new float[] { 12, 4, 2, 2, 2, 6 }, 0);
			case VALLEY:
				return new BasicStroke(1 + d, 0, 0, 1, new float[] { 12, 6}, 0);
			case SUPER_MOUNTAIN:
				return new BasicStroke(2f + d, 0, 0, 1, new float[] { 12, 4, 2, 2, 2, 6 }, 0);
			case SUPER_VALLEY:
				return new BasicStroke(2f + d, 0, 0, 1, new float[] { 12, 6}, 0);
			case EDGE_IN_POLYGON:
				return new BasicStroke(4f);
			}
			return new BasicStroke(2f);
		}

		public static Priority getPriority(DrawScheme scheme)
		{

			switch (scheme)
			{
			case VERTEX:
				return Priority.HIGH;
			}

			return Priority.LOW;
		}
	}
}
